home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 41 / Amiga Format CD41 (1999-06)(Future Publishing)(GB)[!][issue 1999-07].iso / -seriously_amiga- / graphics / ifx_antique / antique.c < prev    next >
C/C++ Source or Header  |  1999-04-19  |  6KB  |  208 lines

  1. #include <exec/types.h>
  2. #include <exec/nodes.h>
  3. #include <exec/lists.h>
  4. #include <exec/memory.h>
  5. #include <utility/tagitem.h>
  6. #include <powerup/ppclib/interface.h>
  7. #include <powerup/ppclib/message.h>
  8. #include <powerup/ppclib/tasks.h>
  9. #include <powerup/proto/ppc.h>
  10. #include <PowerUP/PPCLib/object.h>
  11. #include <proto/exec.h>
  12. #include <proto/dos.h>
  13. #include <scan/hooks.h>
  14.  
  15. #include <stdio.h>
  16.  
  17. /* This information is required by the "start.o" startup code. */
  18. char *HookName = "Antique PPC";
  19.  
  20. /* A version string so the Version command works on us. */
  21. char *HookVersion = "\0$VER: Antique PPC 1.0.0 (12.09.98)";
  22.  
  23.  
  24. char *HookText = "Hook_Antique_PPC";
  25. int   HookTextCount = 0;
  26. char **HookStrings[] = { NULL };
  27.  
  28. struct StartupData
  29. {
  30.     ULONG    MsgCount;
  31. };
  32.  
  33. void hook_main (int argc, char **argv)
  34. {
  35. struct Buffer *buf;
  36. int le, te;
  37. UBYTE *red, *grn, *blu;
  38. struct Library        *PPCLibBase;
  39. struct TagItem        MyTags[10];
  40. void            *PPCPort;
  41. void            *ReplyPort;
  42. void            *StartupMsg;
  43. void            *M68kMsg;
  44. void            *PPCMsg;
  45. void            *ElfObject;
  46. void            *Task;
  47. ULONG          *Body;
  48. struct StartupData    *StartupData;
  49. ULONG            i;
  50. ULONG w,h;
  51. extern char   elfobject[];
  52. extern size_t elfobject_size;
  53.  
  54.    /*
  55.     * Get current buffer.
  56.     */
  57.    if (ScanBase->sb_AreaTool == AT_BRUSH)
  58.       buf = ScanBase->sb_Brush;
  59.    else
  60.       buf = ScanBase->MainBuffer;
  61.  
  62.    /*
  63.     * If no buffer, complain and exit.
  64.     */
  65.    if (!buf) {
  66.       SetError(ERR_NoBuffer);
  67.       Error();
  68.       return;
  69.    }
  70.  
  71.    /*
  72.     * Get area to be affected.  If the user has defined a region,
  73.     * then the Buffer->Mask structure defines that region.  We
  74.     * limit our processing to that region.
  75.     */
  76.    if (buf->Mask) {
  77.       le = buf->Mask->OffsetX;
  78.       te = buf->Mask->OffsetY;
  79.       w  = buf->Mask->Width;
  80.       h  = buf->Mask->Height;
  81.    }
  82.    else {
  83.       le = 0;
  84.       te = 0;
  85.       w  = buf->Width;
  86.       h  = buf->Height;
  87.    }
  88.  
  89.   if (PPCLibBase = OpenLibrary("ppc.library", 44))
  90.   {
  91.     if( ElfObject = PPCLoadObjectTags( PPCELFLOADTAG_ELFADDRESS, (ULONG)elfobject,
  92.                                        PPCELFLOADTAG_ELFLENGTH,  (ULONG)elfobject_size,
  93.                                        TAG_DONE ) )
  94.       {
  95.         MyTags[0].ti_Tag    =    TAG_DONE;
  96.         if (ReplyPort = PPCCreatePort(MyTags))
  97.         {
  98.           if (StartupMsg = PPCCreateMessage(ReplyPort, 0))
  99.           {
  100.             if (StartupData = PPCAllocVec(sizeof(struct StartupData), MEMF_ANY))
  101.             {
  102.               StartupData->MsgCount    =    h;
  103.  
  104.               MyTags[0].ti_Tag    =    PPCTASKTAG_STARTUP_MSG;
  105.               MyTags[0].ti_Data    =(ULONG) StartupMsg;
  106.  
  107.               MyTags[1].ti_Tag    =    PPCTASKTAG_STARTUP_MSGDATA;
  108.               MyTags[1].ti_Data    =(ULONG) StartupData;
  109.  
  110.               MyTags[2].ti_Tag    =    PPCTASKTAG_STARTUP_MSGLENGTH;
  111.               MyTags[2].ti_Data    =    0;
  112.  
  113.               MyTags[3].ti_Tag    =    PPCTASKTAG_STARTUP_MSGID;
  114.               MyTags[3].ti_Data    =    0;
  115.  
  116.               MyTags[4].ti_Tag    =    PPCTASKTAG_MSGPORT;
  117.               MyTags[4].ti_Data    =    TRUE;
  118.  
  119.               MyTags[5].ti_Tag    =    PPCTASKTAG_NAME;
  120.               MyTags[5].ti_Data    =    (ULONG)HookName;
  121.  
  122.               MyTags[6].ti_Tag    =    TAG_DONE;
  123.  
  124.               if (Task = PPCCreateTask(ElfObject, MyTags))
  125.               {
  126.                 if (PPCPort=(void*) PPCGetTaskAttrsTags(Task,
  127.                                                         PPCTASKINFOTAG_MSGPORT,0,
  128.                                                         TAG_END))
  129.                 {
  130.                   if (Body = PPCAllocVec(sizeof(ULONG)*5, MEMF_PUBLIC))
  131.                   {
  132.                     if (PPCMsg = PPCCreateMessage(ReplyPort, sizeof(TEXT)))
  133.                     {
  134.  
  135.                       Body[2] = (ULONG)w;
  136.                       Body[3] = (ULONG)le;
  137.  
  138.    /*
  139.     * Save the region we are about to fiddle with into an undo buffer.
  140.     */
  141.    SaveUndo(buf, le, te, w, h);
  142.  
  143.    /*
  144.     * Start a cancel-able status bar.
  145.     */
  146.    BeginBar("Antique PPC", h, TRUE);
  147.  
  148.                       for (i=0;i<h;i++)
  149.                       {
  150.  
  151.       if (Bar(i)) {
  152.          /* Status bar was cancelled if Bar() returns non-zero */
  153.          RestoreUndo(FALSE);  /* restore portion that was already
  154.                                  modified from the undo buffer */
  155.          break;
  156.       }
  157.  
  158.       if (!GetBufLine(buf, &red, &grn, &blu, i + te)) {
  159.          /* Failure means a vmem disk fault of some kind */
  160.          break;
  161.       }
  162.  
  163.                       Body[0] = (ULONG)grn;
  164.                       Body[1] = (ULONG)blu;
  165.  
  166.                         PPCSendMessage(PPCPort,
  167.                                        PPCMsg,
  168.                                        Body,
  169.                                        sizeof(ULONG)*5,
  170.                                        0x12345678);
  171.                         PPCWaitPort(ReplyPort);
  172.                         PPCGetMessage(ReplyPort);
  173.  
  174.                         PutBufLine(buf);
  175.                       }
  176.  
  177.                       for (;;)
  178.                       {
  179.                         if ((M68kMsg=PPCGetMessage(ReplyPort)) == StartupMsg)
  180.                         {
  181.                           break;
  182.                         }
  183.                         else
  184.                         {
  185.                           PPCWaitPort(ReplyPort);
  186.                         }
  187.                       }
  188.  
  189.                       PPCDeleteMessage(PPCMsg);
  190.                     }
  191.                     PPCFreeVec(Body);
  192.                   }
  193.                 }
  194.               }
  195.               PPCFreeVec(StartupData);
  196.             }
  197.             PPCDeleteMessage(StartupMsg);
  198.           }
  199.           PPCDeletePort(ReplyPort);
  200.         }
  201.         PPCUnLoadObject(ElfObject);
  202.       }
  203.     CloseLibrary(PPCLibBase);
  204.   }
  205.    EndBar(NULL);
  206.    RedrawFull();
  207. }
  208.